<template>
  <a-form :form="form">
    用户名：<input type="text" v-model="username">
    <br>
    <br>
    邮箱：<input type="text" v-model="email">
    <!-- <a-form-item
      :label-col="formItemLayout.labelCol"
      :wrapper-col="formItemLayout.wrapperCol"
      label="用户名"
    >
      <a-input
        v-model="username"
        v-decorator="[
          'username',
          { rules: [{ required: true, message: 'Please input your name' }] },
        ]"
        placeholder="Please input your name"
      />
    </a-form-item> -->
    <!-- <a-form-item
      :label-col="formItemLayout.labelCol"
      :wrapper-col="formItemLayout.wrapperCol"
      label="邮箱"
    >
      <a-input
        v-model="email"
        v-decorator="[
          'nickname',
          { rules: [{ required: checkNick, message: 'Please input your nickname' }] },
        ]"
        placeholder="Please input your nickname"
      />
    </a-form-item> -->
    <a-form-item :label-col="formTailLayout.labelCol" :wrapper-col="formTailLayout.wrapperCol">
      <!-- <a-checkbox :checked="checkNick" @change="handleChange">
        Nickname is required
      </a-checkbox> -->
    </a-form-item>
    <a-form-item :label-col="formTailLayout.labelCol" :wrapper-col="formTailLayout.wrapperCol">
      <a-button type="primary" @click="check">
        发送邮箱
      </a-button>
    </a-form-item>
  </a-form>
</template>

<script>
const formItemLayout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 8 },
};
const formTailLayout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 15, offset: 4 },
};
import axios from 'axios'
export default {
  data() {
    return {
      username:'',
      email:'',
      checkNick: false,
      formItemLayout,
      formTailLayout,
      form: this.$form.createForm(this, { name: 'dynamic_rule' }),
    };
  },
  methods: {
    check() {
      let data={
        'username':this.username,
        'email':this.email
      }
      axios.post('http://127.0.0.1:8000/user/email/',{'username':this.username,'email':this.email}).then(res=>{
        if(res.data.code==200){
          console.log(res.data)
          alert(res.data.msg)
          this.$router.push('/Update')
        }
      })

      // this.form.validateFields(err => {
      //   if (!err) {
      //     console.info('success');
      //   }
      // });
    },
    handleChange(e) {
      this.checkNick = e.target.checked;
      this.$nextTick(() => {
        this.form.validateFields(['nickname'], { force: true });
      });
    },
  },
};
</script>
